import { useRef } from 'react'

export const useScrollToBottom = () => {
  // for auto-scroll
  const scrollRef = useRef<HTMLDivElement>(null)

  function scrollDomToBottom() {
    const dom = scrollRef.current
    console.log(dom)
    if (dom) {
      requestAnimationFrame(() => {
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        dom.scrollTo(0, dom.scrollTopMax)
      })
    }
  }

  return {
    scrollRef,
    scrollDomToBottom,
  }
}
